package com.lanou.zakerproject.community;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lanou.zakerproject.R;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/8.
 */
public class CommunityFragment extends Fragment {
    private ArrayList<Fragment> datas;
    private ViewPager viewPager;
    private TabLayout tabLayout;
    private CommunityAdapter communityAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_community, null);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        viewPager = (ViewPager) view.findViewById(R.id.community_viewpager);
        tabLayout = (TabLayout) view.findViewById(R.id.community_tablayout);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        datas = new ArrayList<>();
        datas.add(new ConcernFragment());
        datas.add(new ChoiceFragment());
        datas.add(new FindFragment());

        communityAdapter = new CommunityAdapter(getChildFragmentManager(), datas, getActivity());
        viewPager.setAdapter(communityAdapter);
        tabLayout.setTabTextColors(Color.BLACK, Color.RED);
        tabLayout.setSelectedTabIndicatorColor(Color.RED);
        tabLayout.setupWithViewPager(viewPager);
    }
}
